package com.gym.code.generator;

import java.util.concurrent.ConcurrentHashMap;

import org.apache.commons.lang.StringUtils;

import com.gym.code.generator.utils.LocalStringUtils;


/**
 * 
 * @author xinchun.wang
 * @email: 532002108@qq.com
 * @createTime 2015-4-11 下午12:16:35
 */
public abstract class EnumContants {

	public static enum MethodOperateType implements EnumIdAware {
		select(0), insert(1), update(2), delete(3);

		private MethodOperateType(int id) {
			this.id = id;
		}

		private int id;

		public int getId() {
			return this.id;
		}

		public static MethodOperateType getById(int id) {
			for (MethodOperateType item : values()) {
				if (item.getId() == id) {
					return item;
				}
			}
			return null;
		}
	}

	/**
	 * 字段数据类型
	 * @author xinchun.wang 
	   @email: 532002108@qq.com
	 * @createTime 2015-7-19 上午11:06:05
	 */
	public static class FieldClassType {
		public static final ConcurrentHashMap<String,FieldClassType> instanceMap  = new ConcurrentHashMap<String,FieldClassType>();
		public static final FieldClassType varchar = new FieldClassType( "String","String",true);
		public static final FieldClassType numberInt = new FieldClassType( "int","Integer",true);
		public static final FieldClassType numberLong = new FieldClassType( "long","Long",true);
		public static final FieldClassType numberDouble = new FieldClassType( "double","Double",true);
		public static final FieldClassType floatDouble = new FieldClassType( "float","Float",true);
		public static final FieldClassType date = new FieldClassType(  "Date","Date",true);
		public static final FieldClassType datetime = new FieldClassType(  "Date","Date",true);

		
		
		public static boolean isBetweenAble(FieldClassType type){
			if(StringUtils.equalsIgnoreCase(type.getJavaName(), date.getJavaName())
					||StringUtils.equalsIgnoreCase(type.getJavaName(), numberInt.getJavaName())
					|| StringUtils.equalsIgnoreCase(type.getJavaName(), numberLong.getJavaName())
					|| StringUtils.equalsIgnoreCase(type.getJavaName(), numberDouble.getJavaName())
					|| StringUtils.equalsIgnoreCase(type.getJavaName(), floatDouble.getJavaName())
					){
				return true;
			}
			return false;
		}
		
		
		public static boolean isListAble(FieldClassType type){
			if(StringUtils.equalsIgnoreCase(type.getJavaName(), numberInt.getJavaName())
					|| StringUtils.equalsIgnoreCase(type.getJavaName(), numberLong.getJavaName())
					){
				return true;
			}
			return false;
		}
		
		public static FieldClassType instance(String javaName) {
			if(instanceMap.get(javaName.toUpperCase()) != null){
				return instanceMap.get(javaName.toUpperCase());
			}
			return new FieldClassType(javaName);
		}

		private FieldClassType(String javaName) {
			if(instanceMap.get(javaName.toUpperCase()) == null){
				instanceMap.putIfAbsent(javaName.toUpperCase(), this);
			}
			this.name = "int";
			this.javaName = javaName;
			this.isJdkDefine = false;
		}
		
		private FieldClassType(String name,String javaName,boolean isJdkDefine) {
			if(instanceMap.get(javaName.toUpperCase()) == null) {
				instanceMap.putIfAbsent(javaName.toUpperCase(), this);
			}
			this.name = name;
			this.javaName = javaName;
			this.isJdkDefine = isJdkDefine;
		}

		private String name;
		private String javaName;
		private boolean isJdkDefine;

		public String getName() {
			return this.name;
		}
		
		public String getNameByFirstLetterUpper() {
			return LocalStringUtils.toFirstLetterUpper(this.name);
		}
		
		public String getJavaName() {
			return javaName;
		}

		public static boolean isNumerType(FieldClassType item){
			if(StringUtils.equals(item.getJavaName(), numberInt.getJavaName()) 
					||StringUtils.equals(item.getJavaName(), numberLong.getJavaName()) 
					|| StringUtils.equals(item.getJavaName(), numberDouble.getJavaName()) 
					){
				return true;
			}
			return false;
		}


		public boolean isJdkDefine() {
			return isJdkDefine;
		}
	}
	
	public static enum AccessModifierType implements EnumIdAware,EnumNameAware {
		$private(0,"private"), $protected(1,"protected"), $public(2,"public");

		private AccessModifierType(int id,String name) {
			this.id = id;
			this.name = name;
		}

		private int id;
		private String name;

		public int getId() {
			return this.id;
		}

		public static AccessModifierType getById(int id) {
			for (AccessModifierType item : values()) {
				if (item.getId() == id) {
					return item;
				}
			}
			return null;
		}

		@Override
		public String getName() {
			return this.name;
		}
	}

	public static interface EnumIdAware {
		int getId();
	}
	
	public static interface EnumNameAware {
		String getName();
	}
}
